import {createRouter, createWebHistory} from "vue-router";
import userRegister from "@/components/user/UserRegister.vue";
import userLogin from "@/components/user/UserLogin.vue";
import userLogout from "@/components/user/UserLogout.vue";
import userUpdate from "@/components/user/UserUpdate.vue"

import adminWorkspace from "@/components/user/workspace/AdminWorkspace.vue"
import crowdWorkspace from "@/components/user/workspace/CrowdWorkspace.vue"
import publisherWorkspace from "@/components/user/workspace/PublisherWorkspace.vue"
import uploadForm from "@/components/project/form/UploadForm.vue"
import roughTaskWorkbench from "@/components/task/workbench/roughTask/roughTaskWorkbench.vue"
import detailedTaskWorkbench from "@/components/task/workbench/detailedTask/detailedTaskWorkbench.vue"

const routes = [
    //task的工作台
    {
        name: "detailedTaskWorkbench",
        path: '/task/workbench/detailed',
        component: detailedTaskWorkbench
    },
    {
        name: 'roughTaskWorkbench',
        path: '/task/workbench/rough',
        component: roughTaskWorkbench
    },
    //用户更新
    {
        name: 'update',
        path: '/user/update',
        component: userUpdate
    },

    //用户退出
    {
        name: 'logout',
        path: '/user/logout',
        component: userLogout
    },

    //上传源文件
    {
        name: 'uploadForm',
        path: '/user/publisher/workspace/upload',
        component: uploadForm
    },
    //workspace
    {
        name: 'crowdWorkspace',
        path: '/user/crowd/workspace',
        component: crowdWorkspace
    },
    {
        name: 'adminWorkspace',
        path: '/user/admin/workspace',
        component: adminWorkspace
    },
    {
        name: 'publisherWorkspace',
        path: '/user/publisher/workspace',
        component: publisherWorkspace
    },

    //register
    {
        name: 'userRegister',
        path: '/user/register',
        component: userRegister
    },
    //login
    {
        name: 'userLogin',
        alias: '/',
        path: '/user/login',
        component: userLogin
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

router.beforeEach((to,from)=>{
    const userId = sessionStorage.getItem("user.id");
    if (to.path=="/"||to.path=='/user/login'){
        return true;
    }
    if (userId == null){
        return false;
    }
})

export default router;